const { createPage, BaseVmControl, watch } = require('../../common/frame')
const Nid = require('../../common/nid');

const list = [
    {
        title: "DEMO",
        data: [
            { title: "Anim", url: '/subpack1/pages/anim/index' },
            { title: "Form", url: '/subpack1/pages/form/index' },
            { title: "Grid", url: '/subpack1/pages/grid/index' }
        ]
    },
    {
        title: "API",
        data: [
            { title: "弹窗", action: 'action1' },
        ]
    },
];

class vm2 extends BaseVmControl {
    title = ''
    get TextDetail() {
        return 'my 页面 ' + this.title
    }
    setTitle(v) {
        this.title = v
    }
    action2() {
        this.title = Nid();
    }
}

createPage({
    controls: {
        vm2: vm2
    },
    data: {
        list,
        showDialog1: false,
        getDataField() {
            return 'render from function'
        }
    },
    onLoad() {
        //   console.log(this.$vm2.TextDetail);
        watch(this.$vm2.TextDetail, (newVal) => {
            console.log('newVal', newVal);
        });
        setTimeout(() => {
            this.$vm2.action2()
        }, 3000)
    },
    methods: {
        startSome(e) {
            // console.log(e.target.dataset);
            let dataset = e.target.dataset;

            let item = list[dataset.idx].data[dataset.subidx]
            if (dataset.idx < 1) {
                wx.navigateTo({
                    url: item.url
                })
            }
            else {
                this[item.action]()
            }
        },
        action1() {
            // console.log('action1');
            this.setData({
                showDialog1: true
            })
        },
        closeDialog1() {
            this.setData({
                showDialog1: false
            })
        }
    }
})
